package com.zaoyidian.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zaoyidian.common.Const;
import com.zaoyidian.common.ResponseCode;
import com.zaoyidian.common.ServerResponse;
import com.zaoyidian.dao.ShopMapper;
import com.zaoyidian.pojo.Shop;
import com.zaoyidian.service.IShopService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Gahins on 2017/8/14.
 */
@Service("iShopService")
public class ShopServiceImpl implements IShopService {
    @Autowired
    private ShopMapper shopMapper;

    public ServerResponse<PageInfo> getShopBylocation(String location,int pageNum,int pageSize,String orderBy){
        if(StringUtils.isBlank(location)){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        location =new StringBuilder().append("%").append(location).append("%").toString();
        PageHelper.startPage(pageNum,pageSize);
        // TODO: 2017/8/14  排序处理
        List<Shop> shopList=shopMapper.selectByLocation(location);
        PageInfo pageInfo = new PageInfo(shopList);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
